package be.ipl.diavoloz.modele;

import java.io.Serializable;
import java.util.Random;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Entity
@Table(schema="DIAVOLOZ", name="DE")
public abstract class De implements Serializable{

	private static final long serialVersionUID = -456072347388271621L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id_de;
	
	@Transient
	private Random random = new Random();
	
	@NotNull
	@Max(6) @Min(0)
	private int valeur;
	
	@NotNull
	private String type;
	
	@ManyToOne
	private Partie partie;
	
	protected De(){
	}
	
	public De(String type){
		this.type = type;
	}
	
	public int lancerDe() {
		return valeur = random.nextInt(6) + 1;
	}
	
	public int getValeur(){
		return this.valeur;
	}
	
	public String getType(){
		return this.type;
	}
}
